package org.bilinc.gz001;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;

import javax.swing.*;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.util.*;
import java.util.List;

public class UserInterface extends JFrame {

    private final ModelService mAppModelService;
    private JTable mWorkersInfo;
    private JTable mYearTable;

    private JTable mLeftFooter;
    private JTable mRightFooter;

    private JScrollPane mWorkersScroll;
    private JScrollPane mYearTableScroll;
    private JScrollPane mLeftFooterScroll;
    private JScrollPane mRightFooterScroll;
    private JPopupMenu mPopupMenu;

    private Object[] mDaysOfCurrentYear = new Object[365];
    private static final int SHIFT_RD = 3;
    private static final int FOOTER_H = 200;
    private static final int LEFT_TABLE_W = 573;

    private final Container mContainer;
    private final Dimension mMaxScreenSize;
    private List<Integer> mDividers;
    private int mCurrentRow = -1;
    private boolean mIsLeftClick = false;

    public UserInterface(ModelService modelService) {
        mContainer = getContentPane();
        mAppModelService = modelService;
        mMaxScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
        mDividers = Utils.getDividersList(mAppModelService.getLeftArrayTableData());

        initLeftTableHeader();
        initRightTableHeader();
        initLeftFooter();
        initRightFooter();
        initTableSynchronizer();
        initPopupMenu();

        mContainer.setLayout(new BorderLayout());
        mContainer.add(mWorkersScroll, BorderLayout.WEST);
        mContainer.add(mYearTableScroll, BorderLayout.CENTER);

        final JPanel footer = new JPanel();
        footer.setLayout(new BorderLayout());
        footer.add(mLeftFooterScroll, BorderLayout.WEST);
        footer.add(mRightFooterScroll, BorderLayout.CENTER);
        mContainer.add(footer, BorderLayout.SOUTH);

        setTitle("Demo build. revision 166");
        setSize((int) (mMaxScreenSize.width * 0.9), (int) (mMaxScreenSize.height * 0.7));
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        ToolTipManager.sharedInstance().setEnabled(false);
    }

    private void initLeftTableHeader() {
        final DefaultTableModel workedTableModel = new DefaultTableModel();

        workedTableModel.setDataVector(mAppModelService.getLeftArrayTableData(),
                Utils.WORKED_HEADER);

        mWorkersInfo = new JTable(workedTableModel) {
            @Override
            public boolean isCellEditable(int row, int column) {
                if (mDividers.contains(row)) {
                    return false;
                }
                return super.isCellEditable(row, column);
            }

            protected JTableHeader createDefaultTableHeader() {
                return new GroupableTableHeader(columnModel);
            }
        };

        mWorkersInfo.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        mWorkersInfo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        final TableColumnModel workersColumnModel = mWorkersInfo.getColumnModel();

        final ColumnGroup halfYearHeader = new ColumnGroup("2013 год");//?? what str?
        halfYearHeader.add(workersColumnModel.getColumn(0));
        halfYearHeader.add(workersColumnModel.getColumn(1));
        halfYearHeader.add(workersColumnModel.getColumn(2));
        halfYearHeader.add(workersColumnModel.getColumn(3));

        final ColumnGroup workedHeader = new ColumnGroup("Отработано");
        workedHeader.add(workersColumnModel.getColumn(4));
        workedHeader.add(workersColumnModel.getColumn(5));
        workedHeader.add(workersColumnModel.getColumn(6));
        workedHeader.add(workersColumnModel.getColumn(7));
        workedHeader.add(workersColumnModel.getColumn(8));

        for (int i = 0; i < Utils.WORKED_COLUMN_WIDTH.length; i++) {
            workersColumnModel.getColumn(i).setPreferredWidth(Utils.WORKED_COLUMN_WIDTH[i]);
        }

        final GroupableTableHeader workersTableHeader = (GroupableTableHeader) mWorkersInfo.getTableHeader();
        workersTableHeader.addColumnGroup(halfYearHeader);
        workersTableHeader.addColumnGroup(workedHeader);

        mWorkersScroll = new JScrollPane(mWorkersInfo);
        mWorkersScroll.setPreferredSize(new Dimension(LEFT_TABLE_W, mMaxScreenSize.height - FOOTER_H));
        mWorkersScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);


        final TableColumnModel cm = mWorkersInfo.getColumnModel();
        for (int i = 0; i < Utils.WORKED_HEADER.length; i++) {
            final TableColumn tcol = cm.getColumn(i);
            final WorkedRenderer renderer = new WorkedRenderer();
            renderer.setDividers(mDividers);
            tcol.setCellRenderer(renderer);
        }
        final JTableHeader header = mWorkersInfo.getTableHeader();
        header.setDefaultRenderer(new WorkedHeaderRenderer());
    }

    private void changeRightTableCell(int row, int column, Object aValue) {
        System.out.println("changeRightTableCell row=" + row + " col=" + column);
        Object[] tableData = mAppModelService.onRightTableDataSet(
                Utils.getMonthByYearDay(column),
                Utils.getMonthDayByYearDay(column),
                row, column, aValue, mWorkersInfo.getValueAt(row, 0));
        updateWorkedRow((List<String>) tableData[0], row);
        updateFooterColumn((List<String>) tableData[1], column);
    }

    private void initRightTableHeader() {
        DefaultTableModel yearTableModel = new DefaultTableModel();

        int days = 0;
        ArrayList<Integer> holidays = new ArrayList<Integer>();
        for (int i = 0; i < Utils.MONTHS_COUNT; i++) {
            for (int j = 0; j < Utils.DAYS_PER_MONTH[i]; j++) {
                if (Utils.isHoliday(days)) {
                    holidays.add(days);
                }

                mDaysOfCurrentYear[days] = String.valueOf(j + 1);
                days++;
            }
        }
        yearTableModel.setDataVector(mAppModelService.getRightArrayTableData(),
                mDaysOfCurrentYear);

        mYearTable = new JTable(yearTableModel) {
            public boolean isCellEditable(int row, int column) {
                if (mDividers.contains(row)) {
                    return false;
                }
                return super.isCellEditable(row, column);
            }

            public void setValueAt(Object aValue, int row, int column) {
                if (aValue != null) {
                    if (aValue.equals(";")) {
                        return;
                    }
                }

                if (mIsLeftClick) {
                    System.out.println("mIsLeftClick=");
                    changeRightTableCell(row, column, aValue);
                    mIsLeftClick = false;
                }
                super.setValueAt(aValue, row, column);
            }

            protected JTableHeader createDefaultTableHeader() {
                return new GroupableTableHeader(columnModel);
            }
        };
        mYearTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        mYearTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        final TableColumnModel yearColumnModel = mYearTable.getColumnModel();

        final GroupableTableHeader yearTableHeader = (GroupableTableHeader) mYearTable.getTableHeader();
        days = 0;
        for (int i = 0; i < Utils.MONTHS_COUNT; i++) {
            final ColumnGroup month = new ColumnGroup(AppStrings.MONTHS[i]);
            for (int j = 0; j < Utils.DAYS_PER_MONTH[i]; j++) {
                final TableColumn col = yearColumnModel.getColumn(days);
                col.setPreferredWidth(YearRenderer.DEF_CELL_W);
                final YearRenderer renderer = new YearRenderer();
                renderer.setDividers(mDividers);
                col.setCellRenderer(renderer);
                col.setResizable(false);
                month.add(yearColumnModel.getColumn(days));
                days++;
            }
            yearTableHeader.addColumnGroup(month);
        }
        final YearCellEditor editor = new YearCellEditor();
        editor.setClickCountToStart(1);
        mYearTable.setDefaultEditor(Object.class, editor);

        mYearTableScroll = new JScrollPane(mYearTable);
        mYearTableScroll.setPreferredSize(new Dimension(mMaxScreenSize.width, mMaxScreenSize.height - FOOTER_H));
        mYearTableScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        mYearTableScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

        final String tabAction = "changeRightTableCell";
        KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
        mYearTable.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(enter, tabAction);
        mYearTable.getActionMap().put(tabAction, new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("keyTyped=" + e.getActionCommand());
                JTable table = (JTable) e.getSource();
                ListSelectionModel rowModel = table.getSelectionModel();
                ListSelectionModel colModel = table.getColumnModel().getSelectionModel();

                int rowLead = rowModel.getLeadSelectionIndex();

                int colLead = colModel.getLeadSelectionIndex();
                int colMax = table.getModel().getColumnCount();
                table.clearSelection();
                rowModel.setSelectionInterval(rowLead, rowLead);
                colModel.setSelectionInterval(Math.min(colLead + 1, colMax),
                        Math.min(colLead + 1, colMax));
                int row = table.getSelectedRow();
                int col = table.getSelectedColumn();
                System.out.println("col=" + col + " max=" + colMax);
                table.editCellAt(row, col);
                if (table.getValueAt(row, col - 1) != null) {
                    if (!table.getValueAt(row, col - 1).equals("")) {
                        changeRightTableCell(row, col - 1, table.getValueAt(row, col - 1));
                    }
                }
            }
        });

        final JTableHeader header = mYearTable.getTableHeader();
        YearHeaderRenderer renderer = new YearHeaderRenderer();
        renderer.setHolidays(holidays);
        header.setDefaultRenderer(renderer);
    }

    private void initTableSynchronizer() {
        final ScrollSynchronizer scrollSynchronizer = new ScrollSynchronizer(mWorkersScroll, mYearTableScroll);
        mWorkersScroll.getVerticalScrollBar().addAdjustmentListener(scrollSynchronizer);
        mYearTableScroll.getVerticalScrollBar().addAdjustmentListener(scrollSynchronizer);

        final ScrollSynchronizer scrollSynchronizer1 = new ScrollSynchronizer(mYearTableScroll, mRightFooterScroll);
        mYearTableScroll.getHorizontalScrollBar().addAdjustmentListener(scrollSynchronizer1);
        mRightFooterScroll.getHorizontalScrollBar().addAdjustmentListener(scrollSynchronizer1);
    }

    private void initLeftFooter() {
        final DefaultTableModel leftTableModel = new DefaultTableModel();
        Object[][] initialRows = new Object[AppStrings.LEFT_FOOTER_TITLES.length][1];

        for (int i = 0; i < AppStrings.LEFT_FOOTER_TITLES.length; i++) {
            initialRows[i][0] = AppStrings.LEFT_FOOTER_TITLES[i];
        }
        leftTableModel.setDataVector(initialRows,
                new Object[]{""});

        mLeftFooter = new JTable(leftTableModel) {
            public boolean isCellEditable(int row, int column) {
                return false;
            }

            protected JTableHeader createDefaultTableHeader() {
                return new GroupableTableHeader(columnModel);
            }
        };
        mLeftFooter.setTableHeader(null);
        mLeftFooter.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        mLeftFooterScroll = new JScrollPane(mLeftFooter);
        mLeftFooterScroll.setPreferredSize(new Dimension(LEFT_TABLE_W, FOOTER_H));

        final TableColumnModel cm = mLeftFooter.getColumnModel();
        final TableColumn tcol = cm.getColumn(0);
        tcol.setCellRenderer(new FooterRenderer());
    }

    private void initRightFooter() {
        final DefaultTableModel rightTableModel = new DefaultTableModel();
        rightTableModel.setDataVector(mAppModelService.getFooterArrayTableData(),
                mDaysOfCurrentYear);

        mRightFooter = new JTable(rightTableModel) {
            public boolean isCellEditable(int row, int column) {
                return false;
            }

            protected JTableHeader createDefaultTableHeader() {
                return new GroupableTableHeader(columnModel);
            }
        };

        final TableColumnModel columnModel = mRightFooter.getColumnModel();
        int days = 0;
        for (int i = 0; i < Utils.MONTHS_COUNT; i++) {
            for (int j = 0; j < Utils.DAYS_PER_MONTH[i]; j++) {
                final TableColumn col = columnModel.getColumn(days);
                col.setPreferredWidth(YearRenderer.DEF_CELL_W);
                final FooterRenderer renderer = new FooterRenderer();
                col.setCellRenderer(renderer);

                columnModel.getColumn(days).setPreferredWidth(YearRenderer.DEF_CELL_W);
                days++;
            }
        }

        mRightFooter.setTableHeader(null);
        mRightFooter.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        mRightFooter.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        mRightFooterScroll = new JScrollPane(mRightFooter);
        mRightFooterScroll.setPreferredSize(new Dimension(mMaxScreenSize.width, FOOTER_H));
        mRightFooterScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        mRightFooterScroll.getVerticalScrollBar().setEnabled(false);
    }

    private void initPopupMenu() {
        mPopupMenu = new JPopupMenu("Actions");

        JMenuItem item = new JMenuItem("Добавить строку..");
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.println("Menu item add");
                showAddPersonDialog();
            }
        });
        mPopupMenu.add(item);

        item = new JMenuItem("Удалить строку");
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                if (mCurrentRow != -1) {
                    mIsLeftClick = false;
                    System.out.println("Menu item delete=" + mCurrentRow);
                    removeRow(mCurrentRow);
                    mAppModelService.onRowDelete(mCurrentRow, mWorkersInfo.getValueAt(mCurrentRow, 0));
                    mDividers = Utils.getDividersList(mAppModelService.getLeftArrayTableData());
                    updateWorkedYearRenderers();

                    updateWorked(mAppModelService.getLeftArrayTableData());
                    updateRightFooter(mAppModelService.getFooterArrayTableData());

                }
            }
        });
        mPopupMenu.add(item);

        item = new JMenuItem("Создать отчет..");
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.println("Menu item create report =" + mYearTable.getColumnCount());

                final Object[] calendar = new Object[mYearTable.getColumnCount()];
                for (int i = 0; i < mYearTable.getColumnCount(); i++) {
                    calendar[i] = mYearTable.getValueAt(mCurrentRow, i);
                }
                try {
                    ReportWriter.getInstance().writeReport(
                            null,
                            mAppModelService.findPositionOfResourceByTabNomer((String) mWorkersInfo.getValueAt(mCurrentRow, 0)).getPosition(),
                            (String) mWorkersInfo.getValueAt(mCurrentRow, 0),
                            (String) mWorkersInfo.getValueAt(mCurrentRow, 1),
                            (String) mWorkersInfo.getValueAt(mCurrentRow, 2),
                            calendar);
                } catch (IOException e1) {
                    Utils.showErrorWritingDialog(UserInterface.this);
                } catch (InvalidFormatException e1) {
                    Utils.showErrorWritingDialog(UserInterface.this);
                }
            }
        });
        mPopupMenu.add(item);
    }

    public void aboveListener(ListSelectionListener listener) {
        mWorkersInfo.getSelectionModel().addListSelectionListener(listener);
        mYearTable.getSelectionModel().addListSelectionListener(listener);
    }

    public void belowListener(ListSelectionListener listener) {
        mLeftFooter.getSelectionModel().addListSelectionListener(listener);
        mRightFooter.getSelectionModel().addListSelectionListener(listener);
    }

    public void windowListener(WindowListener listener) {
        addWindowListener(listener);
    }

    public void mouseListener(MouseAdapter listener) {
        mWorkersInfo.addMouseListener(listener);
        mWorkersScroll.addMouseListener(listener);
        mYearTable.addMouseListener(listener);
        mYearTableScroll.addMouseListener(listener);
    }

    public void onWindowClosing() {
        if (Application.DEBUG) {
            System.out.println("Application terminated");
        }
        System.exit(0);
    }

    public void selectAboveTableRow(final int selectedLine) {
        if (selectedLine >= 0) {
            mWorkersInfo.addRowSelectionInterval(selectedLine, selectedLine);
            mYearTable.addRowSelectionInterval(selectedLine, selectedLine);
        }
        //TODO remove below selection
    }

    public void selectBelowTableRow(final int selectedLine) {
        if (selectedLine >= 0) {
            mLeftFooter.addRowSelectionInterval(selectedLine, selectedLine);
            mRightFooter.addRowSelectionInterval(selectedLine, selectedLine);
        }
        //TODO remove above selection
    }

    public void onLeftMouseButton(MouseEvent e) {
        if (Application.DEBUG) {
            System.out.println("onLeftMouseButton");
        }
        mIsLeftClick = true;
    }

    public void onRightMouseButton(MouseEvent e) {
        if (Application.DEBUG) {
            System.out.println("onRightMouseButton");
        }
        mIsLeftClick = false;
    }

    public void onPressedMouseButton(MouseEvent e) {
        if (Application.DEBUG) {
            System.out.println("onPressedMouseButton");
        }
    }

    public void onReleasedMouseButton(MouseEvent e) {
        if (Application.DEBUG) {
            System.out.println("onReleasedMouseButton");
        }

        if (e.isPopupTrigger()) {
            System.out.println("isPopupTrigger");
            Point p = e.getPoint();

            int rowNumber = mWorkersInfo.rowAtPoint(p);
            int cellNumber = mWorkersInfo.columnAtPoint(p);
            if (!mWorkersInfo.isCellEditable(rowNumber, cellNumber)) {
                return;
            }
            if (Application.DEBUG) {
                System.out.println("rowNumber = " + rowNumber);
            }
            mCurrentRow = rowNumber;

            if (rowNumber == -1) {
                mPopupMenu.getComponent(1).setEnabled(false);
                mPopupMenu.getComponent(2).setEnabled(false);
            } else {
                mPopupMenu.getComponent(1).setEnabled(true);
                mPopupMenu.getComponent(2).setEnabled(true);
                selectAboveTableRow(rowNumber);
            }

            mPopupMenu.show(e.getComponent(), e.getX(), e.getY());
        }
    }

    private void updateRightFooter(final Object[][] footerData) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                for (int i = 0; i < footerData.length; i++) {
                    for (int j = 0; j < footerData[0].length; j++) {
                        mRightFooter.setValueAt(footerData[i][j], i, j);
                    }
                }
                mRightFooter.updateUI();
            }
        });
    }

    private void removeRow(final int row) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                DefaultTableModel worked = (DefaultTableModel) mWorkersInfo.getModel();
                worked.removeRow(row);
                DefaultTableModel year = (DefaultTableModel) mYearTable.getModel();
                year.removeRow(row);
                updateWorkedYearRenderers();
            }
        });
    }

    private void updateWorkedYearRenderers() {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                final TableColumnModel cm = mWorkersInfo.getColumnModel();
                for (int i = 0; i < Utils.WORKED_HEADER.length; i++) {
                    final TableColumn tcol = cm.getColumn(i);
                    WorkedRenderer renderer = (WorkedRenderer) tcol.getCellRenderer();
                    renderer.setDividers(mDividers);
                    tcol.setCellRenderer(renderer);
                }
                mWorkersInfo.updateUI();

                final TableColumnModel yearColumnModel = mYearTable.getColumnModel();
                final GroupableTableHeader yearTableHeader = (GroupableTableHeader) mYearTable.getTableHeader();
                int days = 0;
                for (int i = 0; i < Utils.MONTHS_COUNT; i++) {
                    final ColumnGroup month = new ColumnGroup(AppStrings.MONTHS[i]);
                    for (int j = 0; j < Utils.DAYS_PER_MONTH[i]; j++) {
                        final TableColumn col = yearColumnModel.getColumn(days);
                        YearRenderer renderer = (YearRenderer) col.getCellRenderer();
                        renderer.setDividers(mDividers);
                        col.setCellRenderer(renderer);
                        days++;
                    }
                    yearTableHeader.addColumnGroup(month);
                }
                mYearTable.updateUI();
            }
        });
    }

    private void updateWorked(final Object[][] workedData) {
        System.out.println("updateWorked");
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                for (int i = 0; i < workedData.length; i++) {
                    if (mDividers.contains(i)) {
                        for (int j = 0; j < workedData[i].length; j++) {
                            mWorkersInfo.setValueAt(workedData[i][j], i, j);
                        }
                        for (int div = 2; div < Utils.WORKED_HEADER.length; div++) {
                            mWorkersInfo.setValueAt(null, i, div);
                        }
                    } else {
                        for (int j = 0; j < workedData[i].length; j++) {
                            mWorkersInfo.setValueAt(workedData[i][j], i, j);
                            //  System.out.print((String)mWorkersInfo.getValueAt(i,j) + " ");
                        }
                    }
                    //   System.out.println();
                }
                mWorkersInfo.updateUI();
            }
        });
    }

    private void updateYear(final Object[][] yeardData) {
        System.out.println("updateYear");
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                for (int i = 0; i < yeardData.length; i++) {
                    if (mDividers.contains(i)) {
                        for (int div = 0; div < mDaysOfCurrentYear.length; div++) {
                            mYearTable.setValueAt(null, i, div);
                        }
                    } else {
                        for (int j = 0; j < yeardData[i].length; j++) {
                            mYearTable.setValueAt(yeardData[i][j], i, j);
                        }
                    }
                }
                mYearTable.updateUI();
            }
        });
    }

    private void updateWorkedRow(final List<String> rowData, final int row) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                for (int i = 0; i < rowData.size(); i++) {
                    mWorkersInfo.setValueAt(rowData.get(i), row, i + SHIFT_RD);
                }
                mWorkersInfo.updateUI();
            }
        });
    }

    private void updateFooterColumn(final List<String> columnData, final int column) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                for (int i = 0; i < columnData.size(); i++) {
                    mRightFooter.setValueAt(columnData.get(i), i, column);
                }
                mRightFooter.updateUI();
            }
        });
    }

    private void addNewRow() {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                ((DefaultTableModel) mWorkersInfo.getModel()).addRow(new Object[Utils.WORKED_HEADER.length]);
                ((DefaultTableModel) mYearTable.getModel()).addRow(new Object[mDaysOfCurrentYear.length]);
            }
        });
    }

    private void showAddPersonDialog() {
        AddPersonDialog d = new AddPersonDialog(this);
        d.initCity(mAppModelService.getAllCities());
        d.initOtdel(mAppModelService.getAllPositions());
        d.init();
        if (d.isAddBtnPressed()) {
            mIsLeftClick = false;

            System.out.println("tab=" + d.getTabN() + " city=" + d.getCity() + " fio=" + d.getFio()
                    + " otdel=" + d.getOtdel());
            addNewRow();
            mAppModelService.onRowAdd(d.getCity(), d.getFio(), d.getOtdel(), d.getTabN(), mCurrentRow);
            mDividers = Utils.getDividersList(mAppModelService.getLeftArrayTableData());
            updateWorked(mAppModelService.getLeftArrayTableData());

            updateYear(mAppModelService.getRightArrayTableData());
            updateWorkedYearRenderers();
            updateRightFooter(mAppModelService.getFooterArrayTableData());
        }
    }
}